package com.xbongbong.saas.model;

import com.xbongbong.paas.domain.entity.StageLogEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.entity.ClueStageLogEntity;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface ClueStageLogModel {

    /**
     * 计算某些阶段的某些线索，在这些阶段的停留时长
     *
     * @param corpid      公司id
     * @param clueIdIn    要查询的线索ids
     * @param stageCodeIn 要查询的阶段codes
     * @return java.util.Map<java.lang.String, java.lang.Double> 返回map，内部结构为：阶段code--该批线索在该阶段的平均停留时长
     */
    Map<String, Double> getAverageStayTime(String corpid, Set<Long> clueIdIn, List<String> stageCodeIn);

    /**
     * 获取当前阶段记录
     *
     * @param clueId
     * @param corpid
     * @return
     */
    ClueStageLogEntity getNowStageLog(Long clueId, String corpid, Long formId);

    /**
     * 当前阶段的停留时长
     *
     * @param corpid    公司id
     * @param clueId    客户id
     * @return
     * @throws
     */
    String getAverageStayTime(String corpid, Long clueId, Long formId) throws XbbException;

    Integer getEntitysCount(Map<String, Object> param);

    List<ClueStageLogEntity> findEntitys(Map<String, Object> param);
    Integer deleteByStageProcessIdAndDataIdIn(List<Long> dataIdIn, String corpid, Long formId, Long stageProcessId, Long stageId);
    void save(ClueStageLogEntity ClueStageLogEntity);

    void insertBatch(List<ClueStageLogEntity> ClueStageLogEntity);

    ClueStageLogEntity getByKey(Long id, String corpid);

    List<ClueStageLogEntity> updateBatch(List<ClueStageLogEntity> clueStageLogList, String corpid);

    List<ClueStageLogEntity> updateBatch4Script(List<ClueStageLogEntity> clueStageLogList);

    List<ClueStageLogEntity> findStageLogWithoutStage();

    Integer deleteBatch(List<StageLogEntity> stageLogEntityList, String corpid);

    /**
     * 根据dataId 查找当前数据所处阶段
     * @param corpid
     * @param formId
     * @param dataId
     * @return
     */
    ClueStageLogEntity getIsNowStage(String corpid, Long formId, Long dataId);

    Long getAvgStayTime(String corpid, Long stageProcessId, Long stageId);

    List<Long> findUsedStageProcessId(String corpid, Long formId, List<Long> stageProcessIdIn);
}
